import React from 'react'
import '../css/todoInput.css'
import { PEDDING } from './config'

class Input extends React.Component {
    constructor(props) {
        super(props);
        this.state = {

        }
    }

    render() {
        return (
            <div className="input_container">
                <div className="input_left">ToDoList</div>
                <input 
                ref="inpval"
                type="text" 
                className="input_right" 
                placeholder="添加ToDo"
                onKeyDown={(event)=> {
                    var keyCode = event.keyCode;
                    var val = this.refs.inpval.value;
                    if(keyCode === 13) {
                        if(val === ' ') {
                            return
                        }else {
                            var item = {
                                val: val,
                                status: PEDDING
                            }
                            this.props.addVal(item)
                        }
                    }
                }} />
            </div>
        )
    }
}

export default Input